﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

void blankrectangle(char c)
{
    int l, w;
    printf("请分别输入长宽，以空格分开: ");
    scanf("%d %d", &l, &w);
    for (int i = 0; i < l; i++)
    {
        printf("%c", c);
    }
    printf("\n");
    for (int i = 0; i < w - 2; i++)
    {
        printf("%c", c);
        for (int j = 0; j < l - 2; j++)
        {
            printf(" ");
        }
        printf("%c\n", c);
    }
    if (w > 1) {
        for (int i = 0; i < l; i++)
        {
            printf("%c", c);
        }
        printf("\n");
    }
}
void pyramid(char c)
{
    int h;
    printf("请输入金字塔层高: ");
    scanf("%d", &h);
    for (int i = 0; i < h; i++)
    {
        for (int a = 0; a < h - i - 1; a++)
        {
            printf(" ");
        }

        for (int a = 0; a < 2 * i + 1; a++)
        {
            printf("%c", c);
        }
        printf("\n");
    }
}
void rhombus(char c) {
    int h;
    printf("请输入菱形的高度（必须是奇数）: ");
    scanf("%d", &h);
    if (h % 2 == 0) {
        printf("错误：菱形高度必须是奇数！\n");
        return;
    }
    int mid = h / 2;
    for (int i = 0; i <= mid; i++) {
        for (int j = 0; j < mid - i; j++) {
            printf(" ");
        }
        for (int j = 0; j < 2 * i + 1; j++) {
            printf("%c", c);
        }
        printf("\n");
    }
    for (int i = mid - 1; i >= 0; i--) {
        for (int j = 0; j < mid - i; j++) {
            printf(" ");
        }
        for (int j = 0; j < 2 * i + 1; j++) {
            printf("%c", c);
        }
        printf("\n");
    }
}
void chessboard(char c) {
    int a;
    printf("请输入棋盘格边长: ");
    scanf("%d", &a);

    for (int i = 0; i < a; i++)
    {
        for (int j = 0; j < a; j++)
        {
            if ((i + j) % 2 == 0)
            {
                printf("%c", c);
            }
            else {
                printf(" ");
            }
        }
        printf("\n");
    }
}
void triangle(char c) {
    int l;
    printf("请输入长直角边: ");
    scanf("%d", &l);
    for (int i = 0; i < l; i++) {
        for (int j = 0; j <= i; j++) {
            printf("%c", c);
        }
        printf("\n");
    }
}

int main()
{
    char c, choice = '0';
    while (1)
    {
        printf("请输入填充元素并选择填充模式：1-空心矩形  2-金字塔 3-菱形 4-棋盘格 5-直角三角形 6-结束程序\n");
        scanf("%c %c", &c, &choice);
        getchar();

        switch (choice)
        {
        case '1': blankrectangle(c); break;
        case '2': pyramid(c); break;
        case '3': rhombus(c); break;
        case '4': chessboard(c); break;
        case '5': triangle(c); break;
        case '6':return 0; break;
        default: printf("预期外的输入!请重新选择！\n"); break;
        }

        getchar();
    }
}